package odfconverter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.text.DecimalFormat;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;

import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
/*
WriteStartElement:pzip-archive-urn:cleverage:xmlns:post-processings:zip
WriteStartAttribute:pzip-target-urn:cleverage:xmlns:post-processings:zip
WriteString:C:\Documents and Settings\Administrator\Local Settings\Temp\tmp2BA.tmp
WriteEndAttribute
WriteStartAttribute:xmlns-pzip-http://www.w3.org/2000/xmlns/
WriteString:urn:cleverage:xmlns:post-processings:zip
WriteEndAttribute
WriteStartAttribute:xmlns-office-http://www.w3.org/2000/xmlns/
WriteString:urn:oasis:names:tc:opendocument:xmlns:office:1.0
WriteEndAttribute
WriteStartAttribute:xmlns-svg-http://www.w3.org/2000/xmlns/
WriteString:urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0
WriteEndAttribute
WriteStartAttribute:xmlns-xlink-http://www.w3.org/2000/xmlns/
WriteString:http://www.w3.org/1999/xlink
WriteEndAttribute
WriteStartAttribute:xmlns-v-http://www.w3.org/2000/xmlns/
WriteString:urn:schemas-microsoft-com:vml
WriteEndAttribute
WriteStartAttribute:xmlns-o-http://www.w3.org/2000/xmlns/
WriteString:urn:schemas-microsoft-com:office:office
WriteEndAttribute
WriteStartElement:pzip-entry-urn:cleverage:xmlns:post-processings:zip
WriteStartAttribute:pzip-target-urn:cleverage:xmlns:post-processings:zip
WriteString:docProps/core.xml
WriteEndAttribute
WriteString:>
WriteString:	
*/
public class XMLStreamWriterDemo {
  public static void main(String[] args) throws Exception {
		String val = new DecimalFormat("0.##").format(1250322222.335);
		System.out.println("value is:" + val);
		System.out.println(String.valueOf(1250322222.335));
        double d = 3.14159;
        String s;
        s = String.format("%.0f", d);
        System.out.println(s);
        
		String sendDataString = String.format("%d",18563);  
        System.out.println(sendDataString);  
        
	  ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("c:\\data1.zip"));  
String fileName = "yourXML.xml";
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        //xof.setProperty(XMLInputFactory.IS_COALESCING, value)
        XMLStreamWriter xtw = null;
        //xtw = xof.createXMLStreamWriter(new FileWriter(fileName));
        zos.putNextEntry(new ZipEntry("test.xml")); 
        xtw = xof.createXMLStreamWriter(zos);
        
        
		xtw.writeStartElement("pzip","archive","urn:cleverage:xmlns:post-processings:zip");
		//WriteStartAttribute:pzip-target-urn:cleverage:xmlns:post-processings:zip
        xtw.writeAttribute("pzip", "urn:cleverage:xmlns:post-processings:zip", "target","tmp2BA.tmp");
		xtw.writeAttribute("xmlns", "http://www.w3.org/2000/xmlns/", "pzip","urn:cleverage:xmlns:post-processings:zip");
		xtw.writeAttribute("xmlns", "http://www.w3.org/2000/xmlns/", "office","urn:oasis:names:tc:opendocument:xmlns:office:1.0");
	    xtw.writeAttribute("xmlns", "http://www.w3.org/2000/xmlns/", "svg","urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
	    //xtw.writeAttribute("http://www.w3.org/2000/xmlns/", "svg","urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");

	    xtw.writeStartElement("pzip","entry","urn:cleverage:xmlns:post-processings:zip");
        xtw.writeAttribute("pzip", "urn:cleverage:xmlns:post-processings:zip", "target","docProps/core.xml");
        xtw.writeCharacters("sdfsdf");
	    xtw.writeCharacters("7777777");
		xtw.writeCharacters("=======");
        xtw.writeEndElement();
		xtw.writeEndElement();
        /*xtw.writeComment("all elements here are explicitly in the HTML namespace");
        //xtw.writeStartDocument("utf-8", "1.0");
        xtw.setPrefix("html", "http://www.w3.org/TR/REC-html40");
        xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "html");
        xtw.writeNamespace("html", "http://www.w3.org/TR/REC-html40");
        xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "head");
        xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "title");
        xtw.writeCharacters("character");
        xtw.writeEndElement();
        xtw.writeEndElement();
        xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "body");
        xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "p");
        xtw.writeCharacters("another character");
        xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "a");
        xtw.writeAttribute("href", "http://www.java2s.com");
        xtw.writeCharacters("here");
        xtw.writeEndElement();
        xtw.writeEndElement();
        xtw.writeEndElement();
        xtw.writeEndElement();
        xtw.writeEndDocument();
		*/
		
        zos.putNextEntry(new ZipEntry("test33.xml")); 
       
        
		xtw.writeStartElement("pzip","archive","urn:cleverage:xmlns:post-processings:zip");
		//WriteStartAttribute:pzip-target-urn:cleverage:xmlns:post-processings:zip
        xtw.writeAttribute("pzip", "urn:cleverage:xmlns:post-processings:zip", "target","tmp2BA.tmp");
		xtw.writeAttribute("xmlns", "http://www.w3.org/2000/xmlns/", "pzip","urn:cleverage:xmlns:post-processings:zip");
		xtw.writeAttribute("xmlns", "http://www.w3.org/2000/xmlns/", "office","urn:oasis:names:tc:opendocument:xmlns:office:1.0");
	    xtw.writeAttribute("xmlns", "http://www.w3.org/2000/xmlns/", "svg","urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
	    //xtw.writeAttribute("http://www.w3.org/2000/xmlns/", "svg","urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");

	    xtw.writeStartElement("pzip","entry","urn:cleverage:xmlns:post-processings:zip");
        xtw.writeAttribute("pzip", "urn:cleverage:xmlns:post-processings:zip", "target","docProps/core.xml");
        xtw.writeCharacters("sdfsdf");
	    xtw.writeCharacters("888888");
		xtw.writeCharacters("=======");
        xtw.writeEndElement();
		xtw.writeEndElement();

		zos.flush();
		zos.close();
        xtw.flush();
        xtw.close();
        System.out.println("Done");
  }
}